public class Test {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode cur1 = l1, cur2  = l2;
        ListNode dummy = new ListNode(0);
        ListNode tail = dummy;
        int addCUr = 0;
        while(cur1 != null || cur2 != null){
            int val1 = cur1 != null ? cur1.val: 0;
            int val2 = cur2 != null ? cur2.val: 0;
            addCUr += val1; addCUr += val2;
            tail.next = new ListNode(addCUr % 10);
            tail = tail.next;
            addCUr /= 10;
            if(cur1 != null) cur1 = cur1.next;
            if(cur2 != null) cur2 = cur2.next;
        }
        tail.next = addCUr == 0? null: new ListNode(addCUr);
        return dummy.next;
    }
}
